<?php
/**
 * Copy Right IJH.CC
 * Each engineer has a duty to keep the code elegant
 * $Id$
 */

if(!defined('__CORE_DIR')){
    exit("Access Denied");
}

class Ctl_Clouddesign_Design extends Ctl
{
    public function index()
    {
        print_r("111"); exit();
//        $user = $this->MEMBER;
//        if(!($user['uid']>0)){
//            $this->err->add('您还没有登录，不能设计', 101);
//        }else{
//            $urlParam = '/p/openapi/login?';
//            //必选参数
//            $urlParam .= 'appuid='.$user['uid'];
//            $urlParam .= '&appuname=\'\'';
//            $urlParam .= '&appuemail=\'\'';
//            $urlParam .= '&appuphone=\'\'';
//            $urlParam .= '&appussn=\'\'';
//            $urlParam .= '&appuaddr=\'\'';
//            $urlParam .= '&appuavatar=\'\'';
//            //可选参数
//            $urlParam .= '&dest=4';
//            $result = K::M('clouddesign/design')->invokeapi($user['uid'], $urlParam, 'POST');
//            //print_r($result);exit();
//            //header("Location:".$result->errorMsg);
//            //exit();
//            $this->pagedata['result'] = $result;
//
//            $this->tmpl = 'clouddesign/design.html';
//        }
    }

    //编辑3D方案
    public function edit3d($designid)
    {
        $user = $this->MEMBER;
        $urlParam = '/p/openapi/login?';
        //必选参数
        $urlParam .= 'appuid='.$user['uid'];
        $urlParam .= '&appuname=\'\'';
        $urlParam .= '&appuemail=\'\'';
        $urlParam .= '&appuphone=\'\'';
        $urlParam .= '&appussn=\'\'';
        $urlParam .= '&appuaddr=\'\'';
        $urlParam .= '&appuavatar=\'\'';
        //可选参数
        $urlParam .= '&dest=1';
        $urlParam .= '&designid='.$designid;
        $result = K::M('clouddesign/design')->invokeapi($user['uid'], $urlParam, 'POST');
        $this->pagedata['result'] = $result;
        $this->tmpl = 'clouddesign/design.html';
    }

    //删除3D方案
    public function delete3d($designid)
    {
        $user = $this->MEMBER;
        $urlParam = '/p/openapi/design/'.$designid.'?';
        $result = K::M('clouddesign/design')->invokeapi('', $urlParam, 'DELETE');
        //print_r($result);exit();
        if($result == 'success'){
            $this->err->add('删除成功');
        }else{
            $this->err->add('删除失败');
        }
    }

    public function submit3d(){
        $user = $this->MEMBER;
        $designid = $this->GP('designid');
        $name = $this->GP('name');
        $mainPic = $this->GP('mainPic');
        $data = array(
            'uid'=>$user['uid'],
            'user_name'=>$user['name'],
            'designid'=>$designid,
            'mainPic'=>$mainPic
        );
        $result = K::M('clouddesign/design')->create($data);
        echo($result);
    }
}